// mylog
package log

import (
	"time"
)

var m *mem
var log_chan chan string

type mylog interface {
	Add(log string)
	Query() string
}

type mem struct {
	_logs map[string]bool
}

func New() mem {
	if m == nil {
		m = new(mem)
		m._logs = make(map[string]bool, 100000)
		log_chan = make(chan string, 100000)

		go m.add()
	}

	return *m
}

func (m *mem) Add(log string) {
	log_chan <- log
}

func (m *mem) Query() string {
	ls := "<html>"
	for l, _ := range m._logs {
		ls += l + "</br>"
	}

	return ls + "</html>"
}

func (m *mem) add() {
	for log := range log_chan {
		log += time.Now().String()
		m._logs[log] = true
	}

}
